home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / javax / swing / UIManager.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  12.3 KB  |  548 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.Insets;
  8. import java.awt.KeyboardFocusManager;
  9. import java.awt.Toolkit;
  10. import java.beans.PropertyChangeListener;
  11. import java.io.File;
  12. import java.io.Serializable;
  13. import java.lang.reflect.Method;
  14. import java.security.AccessController;
  15. import java.util.ArrayList;
  16. import java.util.Locale;
  17. import java.util.Properties;
  18. import java.util.StringTokenizer;
  19. import java.util.Vector;
  20. import javax.swing.border.Border;
  21. import javax.swing.event.SwingPropertyChangeSupport;
  22. import javax.swing.plaf.ComponentUI;
  23. import javax.swing.plaf.metal.MetalLookAndFeel;
  24. import sun.awt.PaintEventDispatcher;
  25. import sun.security.action.GetPropertyAction;
  26. import sun.swing.DefaultLookup;
  27. import sun.swing.SwingUtilities2;
  28.  
  29. public class UIManager implements Serializable {
  30.    private static final Object classLock = new Object();
  31.    private static Thread currentLAFStateThread = null;
  32.    private static LAFState currentLAFState = null;
  33.    private static final String defaultLAFKey = "swing.defaultlaf";
  34.    private static final String auxiliaryLAFsKey = "swing.auxiliarylaf";
  35.    private static final String multiplexingLAFKey = "swing.plaf.multiplexinglaf";
  36.    private static final String installedLAFsKey = "swing.installedlafs";
  37.    private static final String disableMnemonicKey = "swing.disablenavaids";
  38.    private static LookAndFeelInfo[] installedLAFs;
  39.  
  40.    private static LAFState getLAFState() {
  41.       Thread var0 = Thread.currentThread();
  42.       if (var0 == currentLAFStateThread) {
  43.          return currentLAFState;
  44.       } else {
  45.          LAFState var1 = (LAFState)SwingUtilities.appContextGet(SwingUtilities2.LAF_STATE_KEY);
  46.          if (var1 == null) {
  47.             synchronized(classLock) {
  48.                var1 = (LAFState)SwingUtilities.appContextGet(SwingUtilities2.LAF_STATE_KEY);
  49.                if (var1 == null) {
  50.                   SwingUtilities.appContextPut(SwingUtilities2.LAF_STATE_KEY, var1 = new LAFState((1)null));
  51.                }
  52.             }
  53.          }
  54.  
  55.          currentLAFStateThread = var0;
  56.          currentLAFState = var1;
  57.          return var1;
  58.       }
  59.    }
  60.  
  61.    private static String makeInstalledLAFKey(String var0, String var1) {
  62.       return "swing.installedlaf." + var0 + "." + var1;
  63.    }
  64.  
  65.    private static String makeSwingPropertiesFilename() {
  66.       String var0 = File.separator;
  67.       String var1 = System.getProperty("java.home");
  68.       if (var1 == null) {
  69.          var1 = "<java.home undefined>";
  70.       }
  71.  
  72.       return var1 + var0 + "lib" + var0 + "swing.properties";
  73.    }
  74.  
  75.    public static LookAndFeelInfo[] getInstalledLookAndFeels() {
  76.       maybeInitialize();
  77.       LookAndFeelInfo[] var0 = installedLAFs;
  78.       LookAndFeelInfo[] var1 = new LookAndFeelInfo[var0.length];
  79.       System.arraycopy(var0, 0, var1, 0, var0.length);
  80.       return var1;
  81.    }
  82.  
  83.    public static void setInstalledLookAndFeels(LookAndFeelInfo[] var0) throws SecurityException {
  84.       LookAndFeelInfo[] var1 = new LookAndFeelInfo[var0.length];
  85.       System.arraycopy(var0, 0, var1, 0, var0.length);
  86.       installedLAFs = var1;
  87.    }
  88.  
  89.    public static void installLookAndFeel(LookAndFeelInfo var0) {
  90.       LookAndFeelInfo[] var1 = getInstalledLookAndFeels();
  91.       LookAndFeelInfo[] var2 = new LookAndFeelInfo[var1.length + 1];
  92.       System.arraycopy(var1, 0, var2, 0, var1.length);
  93.       var2[var1.length] = var0;
  94.       setInstalledLookAndFeels(var2);
  95.    }
  96.  
  97.    public static void installLookAndFeel(String var0, String var1) {
  98.       installLookAndFeel(new LookAndFeelInfo(var0, var1));
  99.    }
  100.  
  101.    public static LookAndFeel getLookAndFeel() {
  102.       maybeInitialize();
  103.       return getLAFState().lookAndFeel;
  104.    }
  105.  
  106.    public static void setLookAndFeel(LookAndFeel var0) throws UnsupportedLookAndFeelException {
  107.       if (var0 != null && !var0.isSupportedLookAndFeel()) {
  108.          String var4 = var0.toString() + " not supported on this platform";
  109.          throw new UnsupportedLookAndFeelException(var4);
  110.       } else {
  111.          LAFState var1 = getLAFState();
  112.          LookAndFeel var2 = var1.lookAndFeel;
  113.          if (var2 != null) {
  114.             var2.uninitialize();
  115.          }
  116.  
  117.          var1.lookAndFeel = var0;
  118.          if (var0 != null) {
  119.             DefaultLookup.setDefaultLookup((DefaultLookup)null);
  120.             var0.initialize();
  121.             var1.setLookAndFeelDefaults(var0.getDefaults());
  122.          } else {
  123.             var1.setLookAndFeelDefaults((UIDefaults)null);
  124.          }
  125.  
  126.          SwingPropertyChangeSupport var3 = var1.getPropertyChangeSupport(false);
  127.          if (var3 != null) {
  128.             var3.firePropertyChange("lookAndFeel", var2, var0);
  129.          }
  130.  
  131.       }
  132.    }
  133.  
  134.    public static void setLookAndFeel(String var0) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
  135.       if ("javax.swing.plaf.metal.MetalLookAndFeel".equals(var0)) {
  136.          setLookAndFeel((LookAndFeel)(new MetalLookAndFeel()));
  137.       } else {
  138.          Class var1 = SwingUtilities.loadSystemClass(var0);
  139.          setLookAndFeel((LookAndFeel)var1.newInstance());
  140.       }
  141.  
  142.    }
  143.  
  144.    public static String getSystemLookAndFeelClassName() {
  145.       String var0 = (String)AccessController.doPrivileged(new GetPropertyAction("swing.systemlaf"));
  146.       if (var0 != null) {
  147.          return var0;
  148.       } else {
  149.          String var1 = (String)AccessController.doPrivileged(new GetPropertyAction("os.name"));
  150.          if (var1 != null) {
  151.             if (var1.indexOf("Windows") != -1) {
  152.                return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
  153.             }
  154.  
  155.             String var2 = (String)AccessController.doPrivileged(new GetPropertyAction("sun.desktop"));
  156.             if ("gnome".equals(var2)) {
  157.                return "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
  158.             }
  159.  
  160.             if (var1.indexOf("Solaris") != -1 || var1.indexOf("SunOS") != -1) {
  161.                return "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
  162.             }
  163.          }
  164.  
  165.          return getCrossPlatformLookAndFeelClassName();
  166.       }
  167.    }
  168.  
  169.    public static String getCrossPlatformLookAndFeelClassName() {
  170.       String var0 = (String)AccessController.doPrivileged(new GetPropertyAction("swing.crossplatformlaf"));
  171.       return var0 != null ? var0 : "javax.swing.plaf.metal.MetalLookAndFeel";
  172.    }
  173.  
  174.    public static UIDefaults getDefaults() {
  175.       maybeInitialize();
  176.       return getLAFState().multiUIDefaults;
  177.    }
  178.  
  179.    public static Font getFont(Object var0) {
  180.       return getDefaults().getFont(var0);
  181.    }
  182.  
  183.    public static Font getFont(Object var0, Locale var1) {
  184.       return getDefaults().getFont(var0, var1);
  185.    }
  186.  
  187.    public static Color getColor(Object var0) {
  188.       return getDefaults().getColor(var0);
  189.    }
  190.  
  191.    public static Color getColor(Object var0, Locale var1) {
  192.       return getDefaults().getColor(var0, var1);
  193.    }
  194.  
  195.    public static Icon getIcon(Object var0) {
  196.       return getDefaults().getIcon(var0);
  197.    }
  198.  
  199.    public static Icon getIcon(Object var0, Locale var1) {
  200.       return getDefaults().getIcon(var0, var1);
  201.    }
  202.  
  203.    public static Border getBorder(Object var0) {
  204.       return getDefaults().getBorder(var0);
  205.    }
  206.  
  207.    public static Border getBorder(Object var0, Locale var1) {
  208.       return getDefaults().getBorder(var0, var1);
  209.    }
  210.  
  211.    public static String getString(Object var0) {
  212.       return getDefaults().getString(var0);
  213.    }
  214.  
  215.    public static String getString(Object var0, Locale var1) {
  216.       return getDefaults().getString(var0, var1);
  217.    }
  218.  
  219.    static String getString(Object var0, Component var1) {
  220.       Locale var2 = var1 == null ? Locale.getDefault() : var1.getLocale();
  221.       return getString(var0, var2);
  222.    }
  223.  
  224.    public static int getInt(Object var0) {
  225.       return getDefaults().getInt(var0);
  226.    }
  227.  
  228.    public static int getInt(Object var0, Locale var1) {
  229.       return getDefaults().getInt(var0, var1);
  230.    }
  231.  
  232.    public static boolean getBoolean(Object var0) {
  233.       return getDefaults().getBoolean(var0);
  234.    }
  235.  
  236.    public static boolean getBoolean(Object var0, Locale var1) {
  237.       return getDefaults().getBoolean(var0, var1);
  238.    }
  239.  
  240.    public static Insets getInsets(Object var0) {
  241.       return getDefaults().getInsets(var0);
  242.    }
  243.  
  244.    public static Insets getInsets(Object var0, Locale var1) {
  245.       return getDefaults().getInsets(var0, var1);
  246.    }
  247.  
  248.    public static Dimension getDimension(Object var0) {
  249.       return getDefaults().getDimension(var0);
  250.    }
  251.  
  252.    public static Dimension getDimension(Object var0, Locale var1) {
  253.       return getDefaults().getDimension(var0, var1);
  254.    }
  255.  
  256.    public static Object get(Object var0) {
  257.       return getDefaults().get(var0);
  258.    }
  259.  
  260.    public static Object get(Object var0, Locale var1) {
  261.       return getDefaults().get(var0, var1);
  262.    }
  263.  
  264.    public static Object put(Object var0, Object var1) {
  265.       return getDefaults().put(var0, var1);
  266.    }
  267.  
  268.    public static ComponentUI getUI(JComponent var0) {
  269.       maybeInitialize();
  270.       ComponentUI var1 = null;
  271.       LookAndFeel var2 = getLAFState().multiLookAndFeel;
  272.       if (var2 != null) {
  273.          var1 = var2.getDefaults().getUI(var0);
  274.       }
  275.  
  276.       if (var1 == null) {
  277.          var1 = getDefaults().getUI(var0);
  278.       }
  279.  
  280.       return var1;
  281.    }
  282.  
  283.    public static UIDefaults getLookAndFeelDefaults() {
  284.       maybeInitialize();
  285.       return getLAFState().getLookAndFeelDefaults();
  286.    }
  287.  
  288.    private static LookAndFeel getMultiLookAndFeel() {
  289.       LookAndFeel var0 = getLAFState().multiLookAndFeel;
  290.       if (var0 == null) {
  291.          String var1 = "javax.swing.plaf.multi.MultiLookAndFeel";
  292.          String var2 = getLAFState().swingProps.getProperty("swing.plaf.multiplexinglaf", var1);
  293.  
  294.          try {
  295.             Class var3 = SwingUtilities.loadSystemClass(var2);
  296.             var0 = (LookAndFeel)var3.newInstance();
  297.          } catch (Exception var4) {
  298.             System.err.println("UIManager: failed loading " + var2);
  299.          }
  300.       }
  301.  
  302.       return var0;
  303.    }
  304.  
  305.    public static void addAuxiliaryLookAndFeel(LookAndFeel var0) {
  306.       maybeInitialize();
  307.       if (var0.isSupportedLookAndFeel()) {
  308.          Vector var1 = getLAFState().auxLookAndFeels;
  309.          if (var1 == null) {
  310.             var1 = new Vector();
  311.          }
  312.  
  313.          if (!var1.contains(var0)) {
  314.             var1.addElement(var0);
  315.             var0.initialize();
  316.             getLAFState().auxLookAndFeels = var1;
  317.             if (getLAFState().multiLookAndFeel == null) {
  318.                getLAFState().multiLookAndFeel = getMultiLookAndFeel();
  319.             }
  320.          }
  321.  
  322.       }
  323.    }
  324.  
  325.    public static boolean removeAuxiliaryLookAndFeel(LookAndFeel var0) {
  326.       maybeInitialize();
  327.       Vector var2 = getLAFState().auxLookAndFeels;
  328.       if (var2 != null && var2.size() != 0) {
  329.          boolean var1 = var2.removeElement(var0);
  330.          if (var1) {
  331.             if (var2.size() == 0) {
  332.                getLAFState().auxLookAndFeels = null;
  333.                getLAFState().multiLookAndFeel = null;
  334.             } else {
  335.                getLAFState().auxLookAndFeels = var2;
  336.             }
  337.          }
  338.  
  339.          var0.uninitialize();
  340.          return var1;
  341.       } else {
  342.          return false;
  343.       }
  344.    }
  345.  
  346.    public static LookAndFeel[] getAuxiliaryLookAndFeels() {
  347.       maybeInitialize();
  348.       Vector var0 = getLAFState().auxLookAndFeels;
  349.       if (var0 != null && var0.size() != 0) {
  350.          LookAndFeel[] var1 = new LookAndFeel[var0.size()];
  351.  
  352.          for(int var2 = 0; var2 < var1.length; ++var2) {
  353.             var1[var2] = (LookAndFeel)var0.elementAt(var2);
  354.          }
  355.  
  356.          return var1;
  357.       } else {
  358.          return null;
  359.       }
  360.    }
  361.  
  362.    public static void addPropertyChangeListener(PropertyChangeListener var0) {
  363.       synchronized(classLock) {
  364.          getLAFState().getPropertyChangeSupport(true).addPropertyChangeListener(var0);
  365.       }
  366.    }
  367.  
  368.    public static void removePropertyChangeListener(PropertyChangeListener var0) {
  369.       synchronized(classLock) {
  370.          getLAFState().getPropertyChangeSupport(true).removePropertyChangeListener(var0);
  371.       }
  372.    }
  373.  
  374.    public static PropertyChangeListener[] getPropertyChangeListeners() {
  375.       synchronized(classLock) {
  376.          return getLAFState().getPropertyChangeSupport(true).getPropertyChangeListeners();
  377.       }
  378.    }
  379.  
  380.    private static Properties loadSwingProperties() {
  381.       if (UIManager.class.getClassLoader() != null) {
  382.          return new Properties();
  383.       } else {
  384.          Properties var0 = new Properties();
  385.          AccessController.doPrivileged(new 1(var0));
  386.          return var0;
  387.       }
  388.    }
  389.  
  390.    private static void checkProperty(Properties var0, String var1) {
  391.       String var2 = System.getProperty(var1);
  392.       if (var2 != null) {
  393.          var0.put(var1, var2);
  394.       }
  395.  
  396.    }
  397.  
  398.    private static void initializeInstalledLAFs(Properties var0) {
  399.       String var1 = var0.getProperty("swing.installedlafs");
  400.       if (var1 != null) {
  401.          Vector var2 = new Vector();
  402.          StringTokenizer var3 = new StringTokenizer(var1, ",", false);
  403.  
  404.          while(var3.hasMoreTokens()) {
  405.             var2.addElement(var3.nextToken());
  406.          }
  407.  
  408.          Vector var4 = new Vector(var2.size());
  409.  
  410.          for(int var5 = 0; var5 < var2.size(); ++var5) {
  411.             String var6 = (String)var2.elementAt(var5);
  412.             String var7 = var0.getProperty(makeInstalledLAFKey(var6, "name"), var6);
  413.             String var8 = var0.getProperty(makeInstalledLAFKey(var6, "class"));
  414.             if (var8 != null) {
  415.                var4.addElement(new LookAndFeelInfo(var7, var8));
  416.             }
  417.          }
  418.  
  419.          installedLAFs = new LookAndFeelInfo[var4.size()];
  420.  
  421.          for(int var9 = 0; var9 < var4.size(); ++var9) {
  422.             installedLAFs[var9] = (LookAndFeelInfo)var4.elementAt(var9);
  423.          }
  424.  
  425.       }
  426.    }
  427.  
  428.    private static void initializeDefaultLAF(Properties var0) {
  429.       if (getLAFState().lookAndFeel == null) {
  430.          String var1 = getCrossPlatformLookAndFeelClassName();
  431.          String var2 = var1;
  432.          String var3 = "<undefined>";
  433.  
  434.          try {
  435.             var3 = var0.getProperty("swing.defaultlaf", var2);
  436.             setLookAndFeel(var3);
  437.          } catch (Exception var7) {
  438.             try {
  439.                var3 = var0.getProperty("swing.defaultlaf", var1);
  440.                setLookAndFeel(var3);
  441.             } catch (Exception var6) {
  442.                throw new Error("can't load " + var3);
  443.             }
  444.          }
  445.  
  446.       }
  447.    }
  448.  
  449.    private static void initializeAuxiliaryLAFs(Properties var0) {
  450.       String var1 = var0.getProperty("swing.auxiliarylaf");
  451.       if (var1 != null) {
  452.          Vector var2 = new Vector();
  453.          StringTokenizer var3 = new StringTokenizer(var1, ",");
  454.  
  455.          while(var3.hasMoreTokens()) {
  456.             String var5 = var3.nextToken();
  457.  
  458.             try {
  459.                Class var6 = SwingUtilities.loadSystemClass(var5);
  460.                LookAndFeel var7 = (LookAndFeel)var6.newInstance();
  461.                var7.initialize();
  462.                var2.addElement(var7);
  463.             } catch (Exception var8) {
  464.                System.err.println("UIManager: failed loading auxiliary look and feel " + var5);
  465.             }
  466.          }
  467.  
  468.          if (var2.size() == 0) {
  469.             var2 = null;
  470.          } else {
  471.             getLAFState().multiLookAndFeel = getMultiLookAndFeel();
  472.             if (getLAFState().multiLookAndFeel == null) {
  473.                var2 = null;
  474.             }
  475.          }
  476.  
  477.          getLAFState().auxLookAndFeels = var2;
  478.       }
  479.    }
  480.  
  481.    private static void initializeSystemDefaults(Properties var0) {
  482.       getLAFState().swingProps = var0;
  483.    }
  484.  
  485.    private static void maybeInitialize() {
  486.       synchronized(classLock) {
  487.          if (!getLAFState().initialized) {
  488.             getLAFState().initialized = true;
  489.             initialize();
  490.          }
  491.  
  492.       }
  493.    }
  494.  
  495.    private static void initialize() {
  496.       Properties var0 = loadSwingProperties();
  497.       initializeSystemDefaults(var0);
  498.       initializeDefaultLAF(var0);
  499.       initializeAuxiliaryLAFs(var0);
  500.       initializeInstalledLAFs(var0);
  501.       String var1 = Toolkit.getDefaultToolkit().getClass().getName();
  502.       if (!"sun.awt.X11.XToolkit".equals(var1) && FocusManager.isFocusManagerEnabled()) {
  503.          KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
  504.       }
  505.  
  506.       if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
  507.          PaintEventDispatcher.setPaintEventDispatcher(new SwingPaintEventDispatcher());
  508.       }
  509.  
  510.       KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(new 2());
  511.  
  512.       try {
  513.          Method var2 = (Method)AccessController.doPrivileged(new 3());
  514.          var2.invoke((Object)null, JComponent.focusController);
  515.       } catch (Exception var3) {
  516.          assert false;
  517.       }
  518.  
  519.    }
  520.  
  521.    // $FF: synthetic method
  522.    static String access$100() {
  523.       return makeSwingPropertiesFilename();
  524.    }
  525.  
  526.    // $FF: synthetic method
  527.    static void access$200(Properties var0, String var1) {
  528.       checkProperty(var0, var1);
  529.    }
  530.  
  531.    static {
  532.       ArrayList var0 = new ArrayList(4);
  533.       var0.add(new LookAndFeelInfo("Metal", "javax.swing.plaf.metal.MetalLookAndFeel"));
  534.       var0.add(new LookAndFeelInfo("CDE/Motif", "com.sun.java.swing.plaf.motif.MotifLookAndFeel"));
  535.       String var1 = (String)AccessController.doPrivileged(new GetPropertyAction("os.name"));
  536.       if (var1 != null && var1.indexOf("Windows") != -1) {
  537.          var0.add(new LookAndFeelInfo("Windows", "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"));
  538.          if (Toolkit.getDefaultToolkit().getDesktopProperty("win.xpstyle.themeActive") != null) {
  539.             var0.add(new LookAndFeelInfo("Windows Classic", "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel"));
  540.          }
  541.       } else {
  542.          var0.add(new LookAndFeelInfo("GTK+", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"));
  543.       }
  544.  
  545.       installedLAFs = (LookAndFeelInfo[])var0.toArray(new LookAndFeelInfo[var0.size()]);
  546.    }
  547. }
  548.